import {
  ComponentType,
  compontent,
  DragFormType,
  elFormItem,
} from "element-easy-form";
import { userTableFields } from "./mock";
import {
  selectDict
} from '/@ts/components/selectDict/index'
let components = [
  ...JSON.parse(JSON.stringify(compontent.children)),
  selectDict,
];
export const getcomponentName = (userTableFields) => {
    let array = []
  for (let index = 0; index < userTableFields.length; index++) {
    const element = userTableFields[index];
    let itemComponent: DragFormType = components.find(
        (itemComponent) => itemComponent.componentName == element.componentName
      );
      if(itemComponent){
        let itemComponentCopy: DragFormType = JSON.parse(JSON.stringify(itemComponent));
        itemComponentCopy.attrsJson.forEach((itemAttrs) => {
          if (itemAttrs.prop == "label") {
            itemAttrs.defaultValue = element.label;
          } else if (itemAttrs.prop == "prop") {
            itemAttrs.defaultValue = element.prop;
          }
        });
        array.push({
          ...itemComponentCopy,
          label: element.label,
          title: element.label,
          prop: element.prop,
        })
      }
     
  }
  return array;
};
